/*
 * @Author: Hp_lucky 1063512385@qq.com
 * @Date: 2024-09-24 14:40:08
 * @LastEditors: Hp_lucky 1063512385@qq.com
 * @LastEditTime: 2024-10-08 12:01:49
 * @FilePath: \lucky-rpg\assets\script\src\Basic\Component\ResourceLabel.ts
 */
import { _decorator, Component, Label, UITransform } from 'cc';
import { autoComp } from '../Manager/BaseManager';
import { SpriteRedefine } from './SpriteRedefine';
import { BaseItem } from '../../Data/Types';
// import { MainModel_Ins } from '../../Game/Main/MainModel';

const { ccclass } = _decorator;

@ccclass('ResourceLabel')
export class ResourceLabel extends Component {
  @autoComp(SpriteRedefine)
  goods_icon: SpriteRedefine;

  @autoComp(Label)
  goods_lab: Label;

  data: BaseItem;

  async updateData(data: BaseItem): Promise<void> {
    // this.data = data;
    // if (this.data instanceof Goods) {
    //   // const g = DataMgr.tables.TbGoods.get(this.data.id);
    //   // this.goods_icon.spriteFrame = await MainModel_Ins.loadDynamicRes<SpriteFrame>(ImagePath.goods_icon + g.imageId + '/spriteFrame');
    //   this.goods_icon.node.active = true;
    //   this.goods_lab.string = this.data.count + '';
    // } else if (this.data instanceof Equip) {
    //   this.goods_icon.node.active = true;
    //   this.goods_lab.string = this.data.count + '';
    // } else if (this.data instanceof AdItem) {
    //   const pf = MultiPlatform.Ins().platform;
    //   // this.goods_icon.spriteFrame = await MainModel_Ins.loadDynamicRes<SpriteFrame>(ImagePath.goods_icon + 'adicon/ad1_' + pf + '/spriteFrame');
    //   this.goods_icon.node.active = true;
    //   this.goods_lab.string = '×' + this.data.count;
    // } else if (this.data instanceof StringItem) {
    //   this.goods_icon.spriteFrame = null;
    //   this.goods_icon.node.active = false;
    //   const iconUi = this.goods_icon.node.getComponent(UITransform);
    //   iconUi.width = 0;
    //   iconUi.height = 0;
    //   const tb = DataMgr.tables.TbText.get(this.data.id);
    //   this.goods_lab.string = tb.str;
    // }
  }

  async updateDataByHas(data: BaseItem, has: number): Promise<void> {
    this.data = data;
    // if (this.data instanceof Goods) {
    //   const g = DataMgr.tables.TbGoods.get(this.data.id);
    //   // this.goods_icon.spriteFrame = await MainModel_Ins.loadDynamicRes<SpriteFrame>(ImagePath.goods_icon + g.imageId + '/spriteFrame');
    //   this.goods_icon.node.active = true;
    //   this.goods_lab.string = has + '/' + this.data.count;
    // } else if (this.data instanceof Equip) {
    //   this.goods_icon.node.active = true;
    //   this.goods_lab.string = has + '/' + this.data.count;
    // } else if (this.data instanceof AdItem) {
    //   const pf = MultiPlatform.Ins().platform;
    //   // this.goods_icon.spriteFrame = await MainModel_Ins.loadDynamicRes<SpriteFrame>(ImagePath.goods_icon + 'adicon/ad1_' + pf + '/spriteFrame');
    //   this.goods_icon.node.active = true;
    //   this.goods_lab.string = '(' + has + '/' + this.data.count + ')';
    // } else if (this.data instanceof StringItem) {
    //   this.goods_icon.spriteFrame = null;
    //   this.goods_icon.node.active = false;
    //   const iconUi = this.goods_icon.node.getComponent(UITransform);
    //   iconUi.width = 0;
    //   iconUi.height = 0;
    //   const tb = DataMgr.tables.TbText.get(this.data.id);
    //   this.goods_lab.string = tb.str;
    // }
  }

  setLab(str: string) {
    this.goods_icon.spriteFrame = null;
    this.goods_icon.node.active = false;
    const iconUi = this.goods_icon.node.getComponent(UITransform);
    iconUi.width = 0;
    iconUi.height = 0;
    this.goods_lab.string = str;
  }
}
